package com.linkedbear.springboot.assemble.c_conditional.condition;

import com.linkedbear.springboot.assemble.component.Boss;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
@Slf4j
public class ExistBossCondition implements Condition {

    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
//        return context.getBeanFactory().containsBeanDefinition("Boss"); // Boss.class.getName()

        boolean flag = context.getBeanFactory().containsBeanDefinition(Boss.class.getName());
        log.info("是否符合条件: {}", flag);
        System.out.println("是否符合条件:"+flag);
        return context.getBeanFactory().containsBeanDefinition(Boss.class.getName());

//        String[] beanNames = context.getBeanFactory().getBeanNamesForType(Boss.class);
//        return beanNames.length > 0;
//        return true;
    }
}
